<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <h2>
        <cpn></cpn>
        <cpn ref="aaa"></cpn>
      </h2>
      <button @click="btnClick">查看</button>
    </div>

    <template id="cpn">
      <div>我是子组件</div>
    </template>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {},
        methods: {
          btnClick() {
            console.log(this.$children);
            console.log(this.$children[0].foo);
            console.log(this.$refs);
          },
        },
        components: {
          cpn: {
            template: "#cpn",
            methods: {
              show() {
                console.log("子组件的show方法");
              },
            },
            data() {
              return {
                foo: "hello,i am a sub component",
              };
            },
          },
        },
      });
    </script>
  </body>
</html>
